<template>
  <div class="take">
    <div class="left">
      <img v-lazy="data.member.avatar"/>
      <span>{{ hiddenName(data.member.nickname) }}</span>
    </div>
    <div class="right">
      <div class="top">
        <star :score="data.score"/>
        <span v-for="spec in data.orderInfo.specs">
          {{ spec.name }}: {{ spec.nameValue }}
        </span>
      </div>
      <div class="center">
        {{ data.content }}
        <good-take-preview :data="data.pictures"/>
      </div>
      <div class="bottom">
        <span>{{ data.createTime }}</span>
        <span>
          <i class="iconfont icon-dianzan"/>
          {{ data.praiseCount }}
        </span>
      </div>
    </div>
  </div>
</template>

<script lang="ts"
        setup>
import GoodTakePreview from '@/components/library/GoodTakePreview.vue'
import Star from '@/components/library/Star.vue'
import type {Take} from '@/types/take'

defineProps<{
  data: Take
}>()

// 隐藏姓名中间的字符
function hiddenName(name: string): string {
  if (name.length <= 2) {
    return name.replace(/./, '*')
  }
  let res: string = ''
  let len: number = name.length - 2
  for (let i = 0; i < len; i++) {
    res += '*'
  }
  return name[0] + res + name[name.length - 1]
}
</script>

<style lang="less"
       scoped>
.take {
  display: flex;
  justify-content: space-between;
  padding: 25px 10px;
  color: #666666;
  border-bottom: 1px solid #f5f5f5;

  .left {
    width: 160px;
    line-height: 40px;

    img {
      width: 40px;
      height: 40px;
      margin-right: 10px;
    }
  }

  .right {
    flex: 1;

    .top {
      line-height: 40px;
      display: flex;

      span {
        margin-left: 10px;
      }
    }
  }

  .center {
    line-height: 24px;
  }

  .bottom {
    display: flex;
    justify-content: space-between;
    color: #999999;
    margin-top: 8px;
  }
}
</style>